package org.jeecg.modules.online.cgform.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.TuringBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.online.cgform.entity.OnlCgformButton;
import org.jeecg.modules.online.cgform.service.IOnlCgformButtonService;
import org.jeecg.modules.online.cgform.utils.BuiltInButtonUtils;
import org.jeecg.modules.online.cgform.utils.CgformUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/online/cgform/button"})
@RestController("onlCgformButtonController")
/* renamed from: org.jeecg.modules.online.cgform.c.b */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/c/b.class */
public class OnlCgformButtonController {

    /* renamed from: a */
    private static final Logger f147a = LoggerFactory.getLogger(OnlCgformButtonController.class);
    @Autowired
    private IOnlCgformButtonService onlCgformButtonService;

    @GetMapping({"/list/{code}"})
    /* renamed from: a */
    public Result<IPage<OnlCgformButton>> m459a(OnlCgformButton onlCgformButton, @RequestParam(name = "pageNo", defaultValue = "1") Integer num, @RequestParam(name = "pageSize", defaultValue = "10") Integer num2, HttpServletRequest httpServletRequest, @PathVariable("code") String str) {
        Result<IPage<OnlCgformButton>> result = new Result<>();
        onlCgformButton.setCgformHeadId(str);
        QueryWrapper<OnlCgformButton> initQueryWrapper = QueryGenerator.initQueryWrapper(onlCgformButton, httpServletRequest.getParameterMap());
        initQueryWrapper.notIn("button_code", BuiltInButtonUtils.getButtonCodeSet());
        IPage page = this.onlCgformButtonService.page(new Page(num.intValue(), num2.intValue()), initQueryWrapper);
        result.setSuccess(true);
        result.setResult(page);
        return result;
    }

    @PostMapping({"/add"})
    @CacheEvict(value = {"sys:cache:online:list", "sys:cache:online:form"}, allEntries = true, beforeInvocation = true)
    /* renamed from: a */
    public Result<OnlCgformButton> m460a(@RequestBody OnlCgformButton onlCgformButton) {
        Result<OnlCgformButton> result = new Result<>();
        try {
            this.onlCgformButtonService.saveButton(onlCgformButton);
            if (BuiltInButtonUtils.getButtonCodeSet().contains(onlCgformButton.getButtonCode())) {
                result.success("修改成功！");
            } else {
                result.success("添加成功！");
            }
        } catch (TuringBootException e) {
            result.error500(e.getMessage());
        } catch (Exception e2) {
            f147a.error(e2.getMessage(), e2);
            result.error500("操作失败");
        }
        return result;
    }

    @PostMapping({"/aitest"})
    /* renamed from: a */
    public Result<OnlCgformButton> m462a(@RequestBody JSONArray jSONArray) {
        Result<OnlCgformButton> result = new Result<>();
        for (int i = 0; i < jSONArray.size(); i++) {
            try {
                this.onlCgformButtonService.saveButton((OnlCgformButton) JSONObject.parseObject(jSONArray.getJSONObject(i).toJSONString(), OnlCgformButton.class));
            } catch (Exception e) {
                f147a.error(e.getMessage(), e);
                result.error500("操作失败");
            }
        }
        result.success("添加成功！");
        return result;
    }

    @PutMapping({"/edit"})
    @CacheEvict(value = {"sys:cache:online:list", "sys:cache:online:form"}, allEntries = true, beforeInvocation = true)
    /* renamed from: b */
    public Result<OnlCgformButton> m457b(@RequestBody OnlCgformButton onlCgformButton) {
        return this.onlCgformButtonService.editButton(onlCgformButton);
    }

    @DeleteMapping({"/delete"})
    @CacheEvict(value = {"sys:cache:online:list", "sys:cache:online:form"}, allEntries = true, beforeInvocation = true)
    /* renamed from: a */
    public Result<OnlCgformButton> m461a(@RequestParam(name = "id", required = true) String str) {
        Result<OnlCgformButton> result = new Result<>();
        if (((OnlCgformButton) this.onlCgformButtonService.getById(str)) == null) {
            result.error500("未找到对应实体");
        } else if (this.onlCgformButtonService.removeById(str)) {
            result.success("删除成功!");
        }
        return result;
    }

    @DeleteMapping({"/deleteBatch"})
    @CacheEvict(value = {"sys:cache:online:list", "sys:cache:online:form"}, allEntries = true, beforeInvocation = true)
    /* renamed from: b */
    public Result<OnlCgformButton> m458b(@RequestParam(name = "ids", required = true) String str) {
        Result<OnlCgformButton> result = new Result<>();
        if (str == null || "".equals(str.trim())) {
            result.error500("参数不识别！");
        } else {
            this.onlCgformButtonService.removeByIds(Arrays.asList(str.split(CgformUtil.f233E)));
            result.success("删除成功!");
        }
        return result;
    }

    @GetMapping({"/queryById"})
    /* renamed from: c */
    public Result<OnlCgformButton> m456c(@RequestParam(name = "id", required = true) String str) {
        Result<OnlCgformButton> result = new Result<>();
        OnlCgformButton onlCgformButton = (OnlCgformButton) this.onlCgformButtonService.getById(str);
        if (onlCgformButton == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(onlCgformButton);
            result.setSuccess(true);
        }
        return result;
    }

    @GetMapping({"/builtInList/{formId}"})
    /* renamed from: d */
    public Result<List<OnlCgformButton>> m455d(@PathVariable("formId") String str) {
        return Result.OK(this.onlCgformButtonService.queryBuiltInButtonList(str));
    }
}
